try:
    x = 10 / 0
except ZeroDivisionError:
    print("除零错误！")


try:
    num = int(input("请输入一个整数："))
    result = 10 / num
except ValueError:
    print("请输入有效的整数！")
except ZeroDivisionError:
    print("不能除以零！")

try:
    x = 10 / 0
except Exception as e:
    print(f"发生异常：{e}")


try:
    num = int(input("请输入一个整数："))
    result = 10 / num
except ZeroDivisionError:
    print("不能除以零！")
except ValueError:
    print("请输入有效的整数！")
else:
    print(f"结果是：{result}")


try:
    file = open("example.txt", "r")
    content = file.read()
except FileNotFoundError:
    print("文件未找到！")
finally:
    print("执行清理工作。")
    if 'file' in locals() and not file.closed:
        file.close()
    
class CustomError(Exception):
    """自定义异常类"""
    def __init__(self, message):
        self.message = message
 
# 使用自定义异常
try:
    raise CustomError("这是一个自定义的错误！")
except CustomError as e:
    print(f"捕获自定义异常：{e.message}")


try:
    try:
        num = int(input("请输入一个整数："))
        result = 10 / num
    except ZeroDivisionError:
        print("内部处理：不能除以零！")
except ValueError:
    print("外部处理：请输入有效的整数！")


def divide(a, b):
    if b == 0:
        raise ZeroDivisionError("除数不能为零！")
    return a / b
 
try:
    result = divide(10, 0)
except ZeroDivisionError as e:
    print(f"捕获异常：{e}")